# _*_ coding : utf-8 _*_
# @Time : 2023/12/1 20:57
# @Author : 韩宗森
# @File : 5_请求对象的定制
# @Project : pythonProject

import urllib.request

url = 'https://www.baidu.com/'

# url的组成
# https://www.baidu.com/s?wd=周杰伦
# http/https    www.baidu.com   80/443      s       wd=周杰伦      #
# 协议            主机             端口号      路径      参数          锚点
# http      80
# https     443
# mysql     3306
# oracle    1521
# redis     6379
# mongodb   27017
# User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36'
}
# 因为urlopen方法中不能存储字典所以headers不能传递进去
# 请求对象的定制
request = urllib.request.Request(url=url, headers=headers)

response = urllib.request.urlopen(request)

content = response.read().decode('utf8')

print(content)
